/**
 * Copyright 2016-2018 mobaas.com
 */
package com.mobaas.devops.schedule.job;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.mobaas.devops.ComponentFactory;
import com.mobaas.devops.HostMonitor;
import com.mobaas.devops.model.HostStat;
import com.mobaas.devops.service.HostService;

/**
 * 
 * @author billy zhang
 * 
 */
public class HostMonitorJob extends AbstractJob {

	@Autowired
    private ComponentFactory<HostMonitor> monitorFactory;
	
	@Autowired
	private HostService hostService;
	
	@Override
	protected void doExecute(Map<String, Object> jobData) {
		
		String name = (String)jobData.get("name");
		
		HostMonitor monitor = monitorFactory.getComponent(name);
		List<HostStat> statlist = monitor.getHostStat(jobData);
		
		if (statlist != null && statlist.size() > 0) {
			hostService.saveHostStat(statlist);
		}
	}
	
}
